package com.sanjiaozhou.gameserver.web;

import com.sanjiaozhou.gameserver.model.params.LoginParam;
import com.sanjiaozhou.gameserver.model.entity.User;
import com.sanjiaozhou.gameserver.service.UserService;
import com.sanjiaozhou.gameserver.webNetty.KcpJsonServer;
import com.sun.org.apache.regexp.internal.RE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/auth")
public class AuthController {

    @Autowired
    private UserService userService;

    @Autowired
    private KcpJsonServer kcpJsonServer;

    /**
     * 用户注册
     */
    @PostMapping("/register")
    public Object register(@RequestBody @Validated User user) {
        return userService.register(user);
    }

    /**
     * 用户登录
     */
    @PostMapping("/login")
    public Object login(@RequestBody @Validated LoginParam param) {
        return userService.login(param);
    }

    @PostMapping("/logout")
    public Object logout(@RequestBody @Validated String token) {
        return userService.logout(token);
    }

    @GetMapping("/send")
    public Object sendTest(String s){
        kcpJsonServer.sendLast(s);
        return s;
    }
}